home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10172 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  974 b 

  1. Path: inforamp.net!ts26-11
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to read in binary file?
  5. Date: Wed, 06 Mar 96 07:09:44 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4hjdng$elu@sam.inforamp.net>
  8. References: <4lCptna00iV5Q5qSZK@andrew.cmu.edu>
  9. NNTP-Posting-Host: ts26-11.tor.inforamp.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4lCptna00iV5Q5qSZK@andrew.cmu.edu>,
  13.    "Sang Hyun Park, Shawn" <sangp+@andrew.cmu.edu> wrote:
  14. >trial-1
  15. >------------------------------------------------------------------------
  16. >#include <fstream.h>
  17. >#include <string.h>
  18. >
  19. >void main(void)
  20. >{
  21. > short buf[2000];    // arbitrary size for trial
  22. >  
  23. > ifstream ins("filename.bin");
  24. > ins.get(buf, 2000);   *
  25. >
  26. >}
  27.  
  28. Problems:    A short is 16-bits or 2-bytes long.  
  29.         You should explicitly convert the buf variable.
  30. You should make the following change...
  31.     ins.get((char *)buf, sizeof(short)*2000);
  32.  
  33. I hope this helps.
  34.  
  35. Agrivar
  36.